Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix shallow copying by repeatAppend() #177

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

jacobtylerwalls
Copy link
Member

Fixes #176

@jacobtylerwalls jacobtylerwalls marked this pull request as draft April 13, 2022 13:09
@mscuthbert
Copy link
Member

common.merge is designed to work on {} objects not [] array. Probably needs a line before the l. 143 if to ask if this[key] instanceof Array and then do a deep array copy.

// music21.common.merge(ret[key], this[key]);
ret[key] = this[key];
if (deep) {
common.merge(ret[key], this[key] as any);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing this is not enough. Probably need to do something more like:

Split the section beginning:
for (const key in this) {
into its own method (common.cloneHelper?) (i.e. a function that doesn't use "this" but obj or something like that). And then when encountering another dictionary/object, calling cloneHelper on that.

@mscuthbert mscuthbert closed this Aug 29, 2022
@mscuthbert mscuthbert reopened this Aug 29, 2022
@mscuthbert mscuthbert closed this Jun 24, 2023
@mscuthbert mscuthbert reopened this Jun 24, 2023
@mscuthbert
Copy link
Member

Now that it's 2024, I wonder if we should just be replacing 90% of these calls with structuredClone() and saying that anything beyond the top-level keys needs to be explicitly listed as having its own clone function or needs to be clonable with structuredClone...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

repeatAppend()/clone() makes shallow copies of groups
2 participants